package com.learning.springboot.Thymeleaf.controller;

import com.learning.springboot.Thymeleaf.entity.Person;
import com.learning.springboot.service.DemoService;
import com.learning.springboot.springdataJpa.PersonRepository;
import com.learning.springboot.springdataJpa.customJpa.PersonCustomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by td on 2017/9/12.
 */
@Controller
public class ThymeleafController {
    @Autowired
    private PersonRepository personRepository;

    @Autowired
    private PersonCustomRepository personCustomRepository;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private DemoService demoService;

    @GetMapping("/test")
    public @ResponseBody String i0ndex() {


        Person person = new Person();
        person.setName("zhangsan");
        person.setAge(10);
        person.setId(1233L);

        personRepository.save(person);

        return "index";
    }

    @GetMapping("/list")
    public @ResponseBody List<Person> list(@RequestParam String name) {

        Person person = demoService.savePersonRollback();

        List<Person> personList = new ArrayList<>();
        personList.add(person);


       // Person person = new Person(name,12);
       // int num = personRepository.setname(name);
       // System.out.println(num);

      //  personCustomRepository.doSomething(11111L);


      //  personRepository.findByName("zhangsan", new Sort(Sort.Direction.DESC,"age"));

       // List<Person> list = personRepository.findFirst10ByName("zhangsan");
      //  List<Person> list = personRepository.findByName("zhangsan");

       //  List<Person> list = personRepository.findByAddress(10);

      //  int  a = personRepository.setname("lisi");

        return personList;
    }

}
